﻿using System;
using Kingdee.BOS.Core.CloudModel.Crm;
using System.Collections.Generic;
using Kingdee.BOS.Core.CloudModel;
using Newtonsoft.Json;

namespace MethodSetBus
{
    public class Get_Crm_Material
    {
        /// <summary>
        /// 灵当CRM物料Json拼接
        /// </summary>
        /// <param name="Key">key</param>
        /// <param name="token">认证令牌</param>
        /// <returns>赋值完成的物料实体</returns>
        public string MaterialResult(string Key,string token, Crm_MaterialList set_Material)
        {
            Crm_Material<Crm_MaterialList> _Material = new Crm_Material<Crm_MaterialList>();
            try
            {
                _Material.module = "Products";
                _Material.func = "newApiSave";
                _Material.apikey = Key;
                _Material.token = token;
                _Material.username = "admin";
                _Material.dataList = new List<Crm_MaterialList>();

                Crm_MaterialList _MaterialList = new Crm_MaterialList();
                _MaterialList.product_no = set_Material.product_no;//物料编码
                _MaterialList.productname = set_Material.productname;//产品名称
                _MaterialList.productcode = set_Material.productcode;//编码或条码
                _MaterialList.productcategory = set_Material.productcategory;//产品类别
                _MaterialList.productsheet = set_Material.productsheet;//规格型号
                _MaterialList.cf_5262 = set_Material.ZHYP_MaData.weight;//商品重量
                _MaterialList.unit_price = set_Material.unit_price;//产品报价(RMB)
                _MaterialList.procostprice = set_Material.procostprice;//参考成本价(RMB)
                _MaterialList.qtyinstock = set_Material.qtyinstock;//总库存数量
                _MaterialList.qtyearly = set_Material.qtyearly;//安全库存
                _MaterialList.description = set_Material.description; //备注
                _MaterialList.discontinued = set_Material.discontinued;//禁用
                _MaterialList.productdetails = set_Material.productdetails;//产品详情
                _MaterialList.usageunit = set_Material.usageunit;//计量单位
                _MaterialList.promodifiedby = set_Material.promodifiedby;//修改人
                _MaterialList.prosmownerid = set_Material.prosmownerid; //负责人
                _MaterialList.smcreatorid = set_Material.smcreatorid;//创建人
                _Material.dataList.Add(_MaterialList);
                return JsonConvert.SerializeObject(_Material) ;
            }
            catch (Exception)
            {

                throw;
            }
        }




        public string AccountsResult(string Key, string token, Crm_Accounts set_Material)
        {
            Crm_Material<Crm_Accounts> _Accounts = new Crm_Material<Crm_Accounts>();
            try
            {
                _Accounts.module = "Accounts"; //CRM模块名称
                _Accounts.func = "newApiSave";//操作方式名称
                _Accounts.apikey = Key;//key
                _Accounts.token = token; //认证令牌
                _Accounts.username = "admin";//用户名
                _Accounts.dataList = new List<Crm_Accounts>();
                Crm_Accounts accounts = new Crm_Accounts();
                accounts.account_no = set_Material.account_no;
                accounts.accountname = set_Material.accountname;
                accounts.phone = set_Material.phone;
                accounts.email = set_Material.email;
                accounts.website = set_Material.website;
                accounts.rating = set_Material.rating;
                accounts.leadsource = set_Material.leadsource;
                accounts.industry = set_Material.industry;
                accounts.bill_country = set_Material.bill_country;
                accounts.bill_state = set_Material.bill_state;
                accounts.bill_city = set_Material.bill_city;
                accounts.bill_area = set_Material.bill_area;
                accounts.description = set_Material.description;
                accounts.assigned_user_id = set_Material.assigned_user_id;
                accounts.cf_5314 = "1";
                _Accounts.dataList.Add(accounts);
                return JsonConvert.SerializeObject(_Accounts);
            }
            catch (Exception e)
            {

                throw;
            }
        }
    }
}
